﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Workflow.ComponentModel;
using Microsoft.Crm.Workflow;

namespace CrmContrib.Workflow.Activities.Utilities
{
    [CrmWorkflowActivity("Get Primary Entity ID", "CrmContrib \\ Utilities")]
    public class GetPrimaryEntityIdActivity : Activity
    {
        [CrmOutput("Entity ID")]
        public string EntityId
        {
            get { return (string)GetValue(EntityIdProperty); }
            set { SetValue(EntityIdProperty, value); }
        }

        public static readonly DependencyProperty EntityIdProperty = DependencyProperty.Register("EntityId", typeof(string), typeof(GetPrimaryEntityIdActivity));

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            var contextService = executionContext.GetService<IContextService>();
            var workflowContext = contextService.Context;

            this.EntityId = workflowContext.PrimaryEntityId.ToString();

            return base.Execute(executionContext);
        }
    }
}
